$(function () {

  var id = location.search.split("?")[1].split('=')[1];
  $.get("/cart/getGoodsById", {
    id
  }).done(function (res) {
    let { data } = res;
    console.log(res);
    $(".title p").text(data.name);
    $(".sku-box .sku-name").text(data.name);
    $(".sku-box img").attr("src", data.img);
    $(".newimg img").attr("src", data.img);
    $(".bigswiper img").attr("src", data.img);
    $(".title-li .itle-point").text(data.point);
    $(".title-li .title-desc").text(data.desc);
    $(".price-box .sell-price").text(data.price);
    $(".original-price .s-price").text(data.sprice);
  })

})


// 加入购物车
$(function () {
  $("#btnAddcart").on("click", function () {
    var id = location.search.split("?")[1].split('=')[1];
    var name = $(".title .title-name").text() + $(".title-li .title-desc").text();
    var price = $(".price-box .sell-price").text();
    var number = 1;
    var img = $(".preview-list  .preview-list-item img").attr("src");
    var uId = JSON.parse(sessionStorage.getItem("userinfo") || '{}').uId;



    $.ajax({
      url: "/cart/add",
      type: "post",
      data: {
        id, name, price, number, img, uId
      }
    }).then(function (res) {
      console.log(res);
    })
  })
})

